﻿using AfrikDotnetWebSite.Models;
using System;
using System.Collections.Generic;

namespace AfrikDotnetWebSite.Helpers
{
    public class AdHelper
    {
        public static List<Ad> GetAds()
        {
            using (AfrikDotnetContext db = new AfrikDotnetContext())
            {
                List<Ad> adList = new List<Ad>();
                var ads = db.Ads;

                foreach (var ad in ads)
                {
                    DateTime startDate = ad.StartDate;
                    DateTime expiryDate = startDate.AddDays(ad.Duration);
                    if (DateTime.Now <= expiryDate)
                    {
                        adList.Add(ad);
                    }
                }
                return adList;
            }
        }
    }
}